package contactbook.service.impl;

import contactbook.dao.AccountDAOInterface;
import contactbook.dao.impl.AccountDAO;
import contactbook.model.Account;
import contactbook.service.AccountServiceInterface;

public class AccountService implements AccountServiceInterface {

	private AccountDAOInterface accountDAO;
	
	public AccountService() {
		accountDAO = new AccountDAO();
	}
	
	@Override
	public Account createAccount(Account account) {
		return accountDAO.createAccount(account);
	}

	@Override
	public void deleteAccount(int accountId) {
		if (accountDAO.getAccountById(accountId).isLogged())
			accountDAO.deleteAccount(accountId);
	}

	@Override
	public Account login(String login, String password) {
		return accountDAO.login(login, password);
	}

	@Override
	public void logout() {
		accountDAO.logout();		
	}
	
	@Override
	public Account getAccountById(int accountId) {
		return accountDAO.getAccountById(accountId);
	}
}
